package org.example.cet.demos.domain;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.http.HttpStatus;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result {
    private Integer code;
    private String message;
    private Object data;

    public Result(ResultE resultE, Object data) {
        this.code = resultE.getCode();
        this.message = resultE.getMessage();
        this.data = data;
    }

    public static Result success(){
        return new Result(ResultE.SUCCESS,null);
    }


    public static Result success(Object data){
        return new Result(ResultE.SUCCESS, data);
    }

    public static Result success(ResultE resultE, Object data){
        return new Result(resultE, data);
    }

    public static Result success(String msg, Object data){
        return new Result(HttpStatus.OK.value(),msg, data);
    }
    public static Result success(String msg){
        return new Result(HttpStatus.OK.value(),msg, null);
    }

    public static Result success(ResultE resultE){
        return new Result(resultE, null);
    }
    public static Result error(ResultE resultE){
        return new Result(resultE, null);
    }

    public static Result error(Integer code , String msg){
        return new Result(code , msg, null);
    }

    public static Result error(String msg) {
        return new Result(HttpStatus.INTERNAL_SERVER_ERROR.value(), msg, null);
    }
}
